<?php
/**
 * @copyright (c) iDoo All Rights Reserved
 */

class Option {
    //版本编号
    const IDOO_VERSION = '1.0.0-Beta';
    //头像缩略图最大宽
    const ICON_MAX_W = 140;
    //头像缩略图最大高
    const ICON_MAX_H = 220;
    //附件上传路径
    const UPLOADFILE_PATH = '/uploads/';

    static function get($option){
        $CACHE = Cache::getInstance();
        $options_cache = $CACHE->readCache('options');
        if (isset($options_cache[$option])) {
            return $options_cache[$option];
        }
    }

    static function getAll(){
        $CACHE = Cache::getInstance();
        $options_cache = $CACHE->readCache('options');
        return $options_cache;
    }

    static function getRoutingTable(){
        $routingtable = array(
            // 网站首页
            array(
                'model' => 'Index_Controller',
                'method' => 'route',
                'reg_0' => '{^/(([a-zA-Z0-9]+)\.html)?([\?#].*)?$}',
                ),
            );
        return $routingtable;
    }

    /**
     * 获取允许上传的附件类型
     */
    static function getAttType() {
        //return explode(',', self::get('att_type'));
        return array('jpg','png','jpeg','gif');
    }

    /**
     * 获取附件最大限制,单位字节
     */
    static function getAttMaxSize() {
        //return self::get('att_maxsize') * 1024;
        return 1024*1024;
    }

    /**
     * 更新配置选项
     * @param $name
     * @param $value
     * @param $isSyntax 更新值是否为一个表达式
     */
    static function updateOption($name, $value, $isSyntax = false){
        $DB = Database::getInstance();
        $value = $isSyntax ? $value : "'$value'";
        $DB->query('UPDATE '.DB_PREFIX."options SET option_value=$value where option_name='$name'");
    }
}
